package com.ali.juejin.bind

import android.webkit.WebView
import androidx.databinding.BindingAdapter
import org.jsoup.Jsoup

object BindWebView {
    @BindingAdapter("url")
    @JvmStatic
    fun loadUrl(view: WebView, url:String?){
        url.let {
            view.loadUrl(url)
        }

    }

    @BindingAdapter("html")
    @JvmStatic
    fun loadHtml(view: WebView, html:String?){
        html?.let {
            val doc = Jsoup.parse(html)
            val imgEles = doc.getElementsByTag("img")
            for (element in imgEles) {
                element.attr("width", "100%").attr("max-width","100%").attr("height", "auto")
            }
            view.loadDataWithBaseURL("about:blank",doc.toString(), "text/html", "utf-8", null);
//            view.loadData(html,"text/html","utf-8")
        }

    }
}